package labox.innovation.gameserver.idfactory;

import labox.innovation.config.Config;

/**
 * This class ...
 * 
 * @version $Revision: 1.3.2.1.2.7 $ $Date: 2005/04/11 10:06:12 $
 */
public abstract class IdFactory {

	protected boolean _initialized;

	public static final int FIRST_OID = 0x10000000;//268,435,456

	public static final int LAST_OID = 0x7FFFFFFF;//2,147,483,647

	public static final int FREE_OBJECT_ID_SIZE = LAST_OID - FIRST_OID;

	/*-------------------------------------角色类ID---------------------------------------*/

	/**
	 * 普通NPC
	 */
	public static final int ID_NPC = 0x00;

	/**
	 * 玩家
	 */
	public static final int ID_PLAYER = ID_NPC + 1;

	/**
	 * 召唤类
	 */
	public static final int ID_SUMMON = ID_NPC + 2;

	/**
	 * 陷阱类
	 */
	public static final int ID_TRAP = ID_NPC + 3;

	/**
	 * 诱饵类
	 */
	public static final int ID_DECOY = ID_NPC + 4;
	
	/**
	 * 技能效果类
	 */
	public static final int ID_EFFECTPOINT = ID_NPC + 5;

	/*-------------------------------------物品类ID---------------------------------------*/

	/**
	 * 一般道具类
	 */
	public static final int ID_ETCITEM = 0x10;

	public static final int ID_WEAPON = 0x20;

	public static final int ID_ARMOR = 0x30;

	/*-------------------------------------组织类ID---------------------------------------*/

	public static final int ID_PARTY = 0x40;

	public static final int ID_CLAN = ID_PARTY + 1;
	
	public static final int ID_COUPLE = ID_PARTY + 2;
	
	/*-------------------------------------商品类ID---------------------------------------*/
	
	public static final int ID_MERCHANDISE = 0x50;
	
	
	

	protected static final IdFactory _instance;

	protected IdFactory() {
	}

	static {
		switch (Config.IDFACTORY_TYPE) {
		case Compaction:
			_instance = new CompactionIDFactory();
			break;
		case BitSet:
			_instance = new BitSetIDFactory();
			break;
		case Stack:
			_instance = new StackIDFactory();
			break;
		case GUID:
			_instance = new GUIDFactory();
			break;
		default:
			_instance = null;
			break;
		}
	}

	public boolean isInitialized() {
		return _initialized;
	}

	public static IdFactory getInstance() {
		return _instance;
	}

	public abstract int getNextId();

	public abstract long getNextId(int type);

	/**
	 * return a used Object ID back to the pool
	 * 
	 * @param object
	 *            ID
	 */
	public abstract void releaseId(int id);

	public abstract int size();
}
